package org.xteam.sled.semantic;

import org.xteam.parser.runtime.Span;
import org.xteam.sled.ast.EqOp;
import org.xteam.sled.model.BasePattern;
import org.xteam.sled.model.LabelledPattern;
import org.xteam.sled.semantic.exp.Exp;


public class Temporary implements IDenotable {

	private Exp exp;
	private Field field;

	public Temporary(Exp exp, Field field) {
		this.exp = exp;
		this.field = field;
	}

	@Override
	public Exp projectInt(IEvaluationContext context, Span span) {
		return exp;
	}
	
	public String toString() {
		return "temp(" + exp + ")";
	}

	@Override
	public BasePattern projectPattern(IEvaluationContext context, Span span) {
		if (field != null) {
			return LabelledPattern.constraint(context, span, field, new EqOp(null), exp);
		}
		context.reportError(span, "not an pattern expression");
		return null;
	}

}
